// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1

package menu

import (
	"audio-server/internal/result"
	"net/http"

	"audio-server/internal/logic/menu"
	"audio-server/internal/svc"
	"audio-server/internal/types"

	"github.com/zeromicro/go-zero/rest/httpx"
)

func MenuSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.MenuSaveReq
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := menu.NewMenuSaveLogic(r.Context(), svcCtx)
		resp, err := l.MenuSave(&req)
		if err != nil {
			httpx.OkJsonCtx(r.Context(), w, result.Fail(err.Error()))
		} else {
			httpx.OkJsonCtx(r.Context(), w, result.Success(resp))
		}
	}
}
